#include<iostream>
#include<vector>
#include<queue>
#include<cstring>
#include<cmath>
#include<map>
#include<set>
#include<cstdio>
#include<algorithm>
#define debug(a) cout<<#a<<"="<<a<<endl;
using namespace std;
const int maxn=1100;
typedef long long LL;
inline LL read(){LL x=0,f=1;char ch=getchar();	while (!isdigit(ch)){if (ch=='-') f=-1;ch=getchar();}while (isdigit(ch)){x=x*10+ch-48;ch=getchar();}
return x*f;}
LL col[maxn][maxn],tot=0;
LL ans[maxn*maxn];
bool vis[maxn][maxn];
char ma[maxn][maxn];
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
struct Node{
    LL x,y;
};
void bfs(LL sx,LL sy,LL num,LL n,LL m)
{
    queue<Node>que;
    que.push({sx,sy});
    LL sum=0;
    while(!que.empty()){
        Node now=que.front();que.pop();
        LL x=now.x;LL y=now.y;
        vis[x][y]=true;
        for(LL i=0;i<4;i++){
            LL nx=x+dx[i];LL ny=y+dy[i];
            if(nx<1||nx>n||ny<1||ny>m||vis[nx][ny]) continue;
            if(ma[nx][ny]=='*') sum++;
            if(ma[nx][ny]=='.'){
                que.push({nx,ny});
                col[nx][ny]=num;
                vis[nx][ny]=true;
            }
        }
    }
    ans[num]=sum;
}
int main(void)
{
  cin.tie(0);std::ios::sync_with_stdio(false);
  LL n,m,k;cin>>n>>m>>k;
  for(LL i=1;i<=n;i++){
    for(LL j=1;j<=m;j++){
        cin>>ma[i][j];
    }
  }
  for(LL i=1;i<=n;i++){
    for(LL j=1;j<=m;j++){
        if(!vis[i][j]&&ma[i][j]=='.'){
            col[i][j]=++tot;
            bfs(i,j,tot,n,m);
        }
    }
  }
  while(k--){
    LL x,y;cin>>x>>y;
    LL number=col[x][y];
    cout<<ans[number]<<"\n";
  }
return 0;
}
